package com.henry.imkit.network

import com.henry.imkit.IMManager
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

class IMQueryParameterInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val originalRequest = chain.request()
        val token = IMManager.token
        if (token.isNotEmpty()) {
            val request: Request
            val modifiedUrl = originalRequest.url.newBuilder()
                .addQueryParameter("access_token", token)
                .build()
            request = originalRequest.newBuilder().url(modifiedUrl).build()
            return chain.proceed(request)
        }
        return chain.proceed(originalRequest)
    }
}